﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LunwenYun.Infrastructure.Entities.Repository;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class Purpose : IAccessible<T_Purpose, Purpose>, ILogicEntity<T_Purpose, Purpose>
    {
        public int Id { get; set; }

        public int PeriodicalId { get; set; }

        public int ArticleId { get; set; }

        public DateTime CreateTime { get; set; }

        #region extend
        public Periodical Periodical { get; set; }
        public Article Article { get; set; }
        #endregion

        protected override void Covariant(T_Purpose model)
        {
            if (model != null)
            {
                this.Id = model.Id;
                this.PeriodicalId = model.PeriodicalId;
                this.ArticleId = model.ArticleId;
                this.CreateTime = model.CreateTime;
            }
        }

        protected override T_Purpose Inverter(Purpose model)
        {
            if (model != null)
            {
                return new T_Purpose()
                {
                    ArticleId = model.ArticleId,
                    CreateTime = model.CreateTime,
                    Id = model.Id,
                    PeriodicalId = model.PeriodicalId
                };
            }
            return null;
        }

        public Purpose Set(T_Purpose dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public Purpose LoadPeriodical(Periodical periodical)
        {
            this.Periodical = periodical;
            return this;
        }
        public Purpose LoadPeriodical(T_Periodical t_periodical)
        {
            this.Periodical = new Periodical().Set(t_periodical);
            return this;
        }
        public Purpose LoadArticle(Article article)
        {
            this.Article = article;
            return this;
        }
        public Purpose LoadArticle(T_Article t_article)
        {
            this.Article = new Article().Set(t_article);
            return this;
        }
    }
}
